﻿namespace WMS6.Web.Inventory
{
    using System;
    using System.Collections.Generic;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.StockCountServiceRef;

    public class CCMaintenance : BasePage
    {
        protected Button btnAddDetail;
        protected Button btnDelete;
        protected Button btnDeleteDetail;
        protected Button btnNew;
        protected Button btnSave;
        protected DropDownList ddlStatus;
        protected HtmlForm F5531;
        protected GridView gvCCTag;
        protected HtmlInputHidden hdnFlag;
        protected HtmlInputHidden hdnFrom;
        protected HtmlInputHidden hdnReleaseID;
        protected HtmlHead Head1;
        protected Label lblAllocateRule;
        protected Label lblCreatedBy;
        protected Label lblMsg;
        protected Label lblReleaseDate;
        protected Label lblReleaseID;
        protected Label lblStatus;
        protected HtmlLink mycss;
        protected Label one1;
        protected Label one2;
        protected ScriptManager ScriptManager1;
        protected TextBox txtCreatedBy;
        protected TextBox txtReleaseDate;
        protected TextBox txtReleaseID;
        protected UpdatePanel up1;

        protected void btnAddDetail_Click(object sender, EventArgs e)
        {
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.ddlStatus.SelectedValue.ToUpper() != "NEW")
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("F5740_002");
                }
                else
                {
                    List<string> gInitLocal0 = new List<string> {
                        this.txtReleaseID.Text
                    };
                    List<string> DeleteID = gInitLocal0;
                    this.lblMsg.Text = StockCountServiceClientProxy.GetInstance().DeleteCycleCountRelease(DeleteID) + base.GetGlobalMsgResource("C006");
                    this.hdnFlag.Value = "";
                    this.txtReleaseID.Enabled = true;
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
                this.lblMsg.Visible = true;
            }
        }

        protected void btnDeleteDetail_Click(object sender, EventArgs e)
        {
        }

        protected void btnGoBack_Click(object sender, EventArgs e)
        {
            if (this.hdnFrom.Value == "list")
            {
                base.Response.Redirect("CCReleaseLogList.aspx?from=edit", false);
            }
            else
            {
                base.Response.Redirect("CCReleaseLogQuery.aspx", false);
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
        }

        protected void gvCCTag_Init(object sender, EventArgs e)
        {
            base.InitDetailGridView("F5531", this.gvCCTag);
        }

        protected void gvCCTag_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            (sender as GridView).PageIndex = e.NewPageIndex;
            (sender as GridView).DataSource = (base.DataEntityViewState as CycleCountReleaseInfo).CycleCountTagInfos;
            (sender as GridView).DataBind();
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',2,2) </script>", false);
        }

        protected void gvCCTag_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Cells[0].Text = (e.Row.RowIndex + 1).ToString();
                e.Row.Attributes.Add("onmouseout", "GridViewRowMouseout(this);");
                e.Row.Attributes.Add("onmouseover", "GridViewRowMouseover(this);");
                ((CheckBox) e.Row.FindControl("chbSelect")).Attributes.Add("onclick", "GridViewCheckBoxClick('" + e.Row.ClientID + "')");
            }
        }

        private void LoadData()
        {
            base.BindData2DDLBySysCode(this.ddlStatus, "CCRStatus");
            if (!string.IsNullOrEmpty(base.Request.QueryString["ID"]))
            {
                this.hdnReleaseID.Value = base.Request.QueryString["ID"].ToString();
                this.hdnFlag.Value = "1";
                this.SetCCReleaseInfo2Form();
            }
            else
            {
                this.ddlStatus.SelectedValue = "New";
                this.ddlStatus.Enabled = false;
            }
            if (!string.IsNullOrEmpty(base.Request.QueryString["from"]))
            {
                this.hdnFrom.Value = base.Request.QueryString["from"].ToString();
            }
            if (!string.IsNullOrEmpty(base.Request.QueryString["detail"]))
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',2,2) </script>", false);
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                this.LoadData();
            }
        }

        private void SetCCReleaseInfo2Form()
        {
            try
            {
                string strReleaseID = this.hdnReleaseID.Value.ToString();
                CycleCountReleaseInfo cycleCountReleaseInfo = StockCountServiceClientProxy.GetInstance().GetCycleCountReleaseInfoByID(strReleaseID);
                base.DataEntityViewState = cycleCountReleaseInfo;
                if (cycleCountReleaseInfo != null)
                {
                    this.txtReleaseID.Text = cycleCountReleaseInfo.ReleaseID;
                    this.txtReleaseID.Enabled = false;
                    this.txtReleaseDate.Text = base.GetPreferenceShortDate(cycleCountReleaseInfo.ReleaseDate);
                    this.txtCreatedBy.Text = cycleCountReleaseInfo.CreatedBy;
                    this.ddlStatus.SelectedValue = cycleCountReleaseInfo.Status;
                    base.BindData2GridView(this.gvCCTag, cycleCountReleaseInfo.CycleCountTagInfos);
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
        }
    }
}

